package com.yc.thread;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: concurrent
 * @description: 优先级
 * @author: zy
 * @create: 2022-01-10 11:23
 */
public class Test10_priority {
    public static void main(String[] args) {
        ShowTime2 task = new ShowTime2();
        Thread stt = new Thread(task);
        stt.setPriority(10);
        stt.setName("线程1");  //设置线程名
        stt.start();


        Thread t = new Thread(task, "线程二");
        t.setPriority(1);
        t.start();
    }
}


class ShowTime2 implements Runnable {

    @Override
    // run加入在线程中完成的操作
    public void run() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss S");
        Date d = null;
        while (true) {
            d = new Date();
            System.out.println(Thread.currentThread().getName() + "当前的时间为:" + sdf.format(d));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
